package guda.demox.web.controller;

import guda.demox.biz.common.BizResult;
import guda.demox.biz.common.BizResultHelper;
import guda.demox.web.security.AuthUser;
import guda.demox.web.security.DefaultAuth;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by well on 2017/11/18.
 */
@RestController
public class UserController {


    @RequestMapping("/user/login")
    public BizResult login(HttpServletRequest request) {
        AuthUser authUser  = new AuthUser();
        authUser.setLoginName("test");
        authUser.setRoles(new String[]{"admin"});
        authUser.setPhone("13512341234");
        request.getSession().setAttribute(DefaultAuth.sessionKey,authUser);
        request.getSession().setAttribute(DefaultAuth.sessionKeyUT,"1");
        return BizResultHelper.newSuccess();
    }

    @RequestMapping("/user/loginOut")
    public BizResult loginOut(HttpServletRequest request) {
        request.getSession().removeAttribute(DefaultAuth.sessionKey);
        request.getSession().removeAttribute(DefaultAuth.sessionKeyUT);
        return BizResultHelper.newSuccess();
    }
}
